<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>参数列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card>
      <!-- 警示信息 -->
      <el-alert title="注意: 只允许为第三级分类设置相关参数！" type="warning" show-icon :closable="false">
      </el-alert>
      <!-- 选择商品分类 -->
      <el-row class="cat_opt">
        <el-col>
          <span>选择商品分类:</span>
          <!-- 选择商品分类的级联选择器 -->
          <el-cascader v-model="selectedKeys" ref="cateHandle" :options="allCateTreeList" :props="cateProps"
            @change="handleChanged" clearable></el-cascader>
        </el-col>
      </el-row>
      <!-- tab选项卡 -->
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="动态参数" name="many">
          <!-- 动态参数 -->
          <el-button @click="showAddDialog({ cat_id: cat_id, attr_sel: activeName })" :disabled="buttonDisabled"
            type="primary" size="mini">
            添加参数
          </el-button>
          <el-table border :data="manyData" style="width: 100%">
            <!-- 展开列 -->
            <el-table-column type="expand" label="属性值" width="80">
              <template slot-scope="scope">
                <!-- {{ scope.row }} -->
                <el-tag v-for="(item, index) in scope.row.attr_vals" :key="index" closable
                  @close="delTag(scope.row, index)">{{ item }}</el-tag>
                <!-- 添加选项值 -->
                <!-- 输入文本框 -->
                <el-input v-if="scope.row.inputVisible" v-model="scope.row.inputValue" class="input-new-tag" size="small"
                  ref="saveTagInput" @blur="handleCancel(scope.row)" @keyup.enter.native="addTag(scope.row)"
                  @keyup.esc.native="handleCancel(scope.row)"></el-input>
                <!-- 添加按钮 -->
                <el-button v-else @click="showInput(scope.row)" class="button-new-tag" size="small">
                  + New Tag
                </el-button>
              </template>
            </el-table-column>
            <el-table-column type="index" label="索引" width="80">
            </el-table-column>
            <el-table-column prop="attr_name" label="参数名称">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button @click="showEditDialog(scope.row)" type="primary" icon="el-icon-edit"
                  size="mini">编辑</el-button>
                <el-button @click="delAttr(scope.row)" type="danger" icon="el-icon-delete" size="mini">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="静态属性" name="only">
          <!-- 静态属性 -->
          <el-button @click="showAddDialog({ cat_id: cat_id, attr_sel: activeName })" :disabled="buttonDisabled"
            type="primary" size="mini">
            添加属性
          </el-button>
          <el-table border :data="onlyData" style="width: 100%">
            <!-- 展开列 -->
            <el-table-column type="expand" label="属性值" width="80">
              <template slot-scope="scope">
                <el-tag v-for="(item, index) in scope.row.attr_vals" :key="index" closable
                  @close="delTag(scope.row, index)">{{ item }}</el-tag>
                <!-- 添加选项值 -->
                <!-- 输入文本框 -->
                <el-input v-if="scope.row.inputVisible" v-model="scope.row.inputValue" class="input-new-tag" size="small"
                  ref="saveTagInput" @blur="handleCancel(scope.row)" @keyup.enter.native="addTag(scope.row)"
                  @keyup.esc.native="handleCancel(scope.row)"></el-input>
                <!-- 添加按钮 -->
                <el-button v-else @click="showInput(scope.row)" class="button-new-tag" size="small">
                  + New Tag
                </el-button>
              </template>
            </el-table-column>
            <el-table-column type="index" label="索引" width="80">
            </el-table-column>
            <el-table-column prop="attr_name" label="参数名称">
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button @click="showEditDialog(scope.row)" type="primary" icon="el-icon-edit"
                  size="mini">编辑</el-button>
                <el-button @click="delAttr(scope.row)" type="danger" icon="el-icon-delete" size="mini">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <!-- 添加/编辑  动态参数/静态属性 属性名称 -->
    <EditParams :attrs="activeName === 'only' ? onlyData : manyData" ref="editParamsRef" @on-edit="editAttrNameHandle"></EditParams>
  </div>
</template>

<script>
import Params from './index.js'
export default {
  ...Params
}
</script>

<style lang="scss" scoped>
.cat_opt {
  margin: 15px 0;

  span {
    margin: 15px;
  }
}

.el-tag {
  margin: 10px;
}

// 文本输入框的样式
.input-new-tag {
  width: 120px;
  margin: 10px;
}

// 添加选项值的按钮的样式
.button-new-tag {
  margin: 10px;
}
</style>